package com.haiyou.dc.aggregate.list;

import com.google.common.base.Joiner;

/**
 * 添加泛型
 * @param <E>
 */
public class MyArrayList02<E> {

    private Object[] elementData;
    private int size;
    private static final int DEFAULT_CAPACITY = 10;

    public MyArrayList02() {
        this.elementData = new Object[DEFAULT_CAPACITY];
    }

    public MyArrayList02(int size) {
        this.elementData = new Object[size];
    }

    public void add(E element) {
        elementData[size++] = element;
    }

    @Override
    public String toString() {
        Joiner joiner2 = Joiner.on(",").skipNulls(); //过滤null
        return joiner2.join(elementData);
    }

    public static void main(String[] args) {
        MyArrayList02<Integer> myArrayList01 = new MyArrayList02(20);
        myArrayList01.add(1);
        myArrayList01.add(4);
        System.out.println(myArrayList01);
    }
}
